/*
 * 全名经纪人列表
 * @author 曾文
 * @time 2018/10/19
 * @since 1.0.0
 * */

import React from 'react'
import { connect } from 'dva'
import { Form, Select, Input, DatePicker, Button, Popconfirm, Icon, Modal, Col } from 'antd'
import moment from 'moment';
import { Link, hashHistory } from 'dva/router'
import config from 'config/config'
import { mapStateToProps } from 'utils/view_utils'
import styles from './allBrokerListStyle.less'
import ListPage from 'widget/PageTmpl/ListPage'
import cx from 'classnames'
const Option = Select.Option;
const { RangePicker } = DatePicker;
const { TextArea } = Input;
const dateFormat = 'YYYY/MM/DD';
//权限管理
import FlagBtn from 'widget/FlagBtn/FlagView'
let subElements =  JSON.parse(localStorage.navBar).subElements

const View = function ({ dispatch, model, form }) {

  const { resetFields, getFieldDecorator, validateFields, setFieldsValue } = form
  const { modelObj, namespace } = model
  let { ustdvisibe, why, area, projectList, biz } = modelObj
  // 资讯详情页跳转
  function detailSkip(type, id = '') {
    hashHistory.push({
      pathname: '/home/businessAdmin/allBrokerDetail',
      query: { type, id }
    });
  }
  // 更新State
  function updateState(params) {
    dispatch({
      type: `${namespace}/updateStore`,
      payload: params
    })
  }
  //导出
  function downLoad() {
    dispatch({
      type: `${namespace}/downLoad`,
      payload: {}
    });
  }
  //输入框改变值
  function inputChange(e) {
    why = e
    dispatch({
      type: `${namespace}/updateStore`,
      payload: {why}
    })
  }
  let pageProps = {
    ui: {
      // "api_url": "admin/agent/ltis",
      "api_url": "admin/agent/listBrokerInvite",
      "method": "POST",
      "app": "",
      "params": "",
      // "mockData": mockData,
      "mockData": null,

      "search_bar": {
        "fields": [
          {
            en_name: 'recommenderNameOrMobile',
            zh_name: '上级经纪人',
            elem_type: 'Input',
            elem_valid_type: 'string',
          },
          {
            en_name: 'recommenderRegion',
            zh_name: '上级经纪人区域',
            elem_type: 'Select',
            elem_valid_type: 'string',
            cmpt_items:area
          },
          {
            en_name: 'recommenderProject',
            zh_name: '上级经纪人项目',
            elem_type: 'Select',
            elem_valid_type: 'string',
            cmpt_items: projectList,
            onFocus:()=>{
              console.log("shishi",biz.queryForm,modelObj)
              if(biz.queryForm.recommenderRegion)
              { 
                dispatch({
                  type: `${namespace}/AllEstateList`,
                  payload:{}
                })
              }
            },
          },
          {
            en_name: 'agentNameOrMobile',
            zh_name: '下级经纪人',
            elem_type: 'Input',
            elem_valid_type: 'string',
          },
          {
            en_name: 'date',
            zh_name: '邀约日期', 
            elem_type: "Date",
            format: "YYYY-MM-DD",
            date_limit: 180, //限制选择区间天数
            double: true,
            split_keys: ['registsTimeBegin', 'registsTimeEnd'],
            elem_valid_type: "string"
          },
          {
            en_name: 'inviteStatus',
            zh_name: '邀约状态',
            elem_type: 'Select',
            elem_valid_type: 'string',
            cmpt_items: [{value:0,label:'已邀约'},{value:1,label:'将失效'},{value:2,label:'已失效'}]
          },
          // {
          //   en_name: 'recommenderRegion',
          //   zh_name: '推荐人区域',
          //   elem_type: 'Select',
          //   elem_valid_type: 'string',
          //   cmpt_items: []
          // },
          // {
          //   en_name: 'recommenderProject',
          //   zh_name: '推荐人项目',
          //   elem_type: 'Input',
          //   elem_valid_type: 'string',

          // }
        ],
        // handleParams: (options={}) => {
        //   let {params={}}=options
        //   console.log('handleParams',params)
        //   console.log('search click')
        //   return  options
        // },
        searchHandler: () => {
          console.log('search click')
        },
        resetHandler: () => {
          console.log('reset click')
        },
        searchCallback: params => {
          console.log('search finish', params)
        },
        pasteTargetList: [
          'carName',
        ]
      },
      action_bar:[
       /* {
          func_name: "onBatDel",
          label: "解除绑定",
          rowSelection: (selectedRowKeys, selectedRows) => {},
          render: () => {
              let isDisabled = true;
              if (modelObj.biz && modelObj.biz.selectedRows && modelObj.biz.selectedRows.length != 0 &&subElements.includes(50204)) {
                  isDisabled = false;
              }
              return (
                <Button onClick={() =>  {updateState({ ustdvisibe: true, why:null})}} style={{marginRight:'15px'}} disabled={isDisabled}>
                  解除绑定
                </Button>
              )
          }
      },*/{
        label:'导出',
        // type:'primary',
        render: () => {
          return(
            <FlagBtn node={<Button onClick={() => downLoad()} type='primary'>导出</Button>} btnId={'50203'}> </FlagBtn>
          )
        },
       
      }],
      // 数据表格
      "table":
      {
        "status_params": "status=0",
        "status_text": "全部",
        "scroll": { x: 1310 },
        "fields": [
          {
            "en_name": "key",
            "zh_name": "序号",
            width: 20,
            render: (a, item, index, d, e, f) => {
              return index + 1
            },
          },
          // {
          //   "en_name": "brokerId",
          //   "zh_name": "经纪人编号",
          // },
          {
            "en_name": "recommenderName",
            "zh_name": "上级经纪人姓名",
            width:135
          },
          {
            "en_name": "recommenderMobile",
            "zh_name": "上级经纪人手机号",
            width:135
          },
          {
            "en_name": "respectiveRegion",
            "zh_name": "上级经纪人区域",
            width:110,
          },
          {
            "en_name": "productNames",
            "zh_name": "上级经纪人项目",
            render:(a, item, index, d, e, f)=>{
              if(item.productNames && item.productNames.length >0){
                return item.productNames.join('，')
              }
              return item.productNames
            },
            width:190
          },
          {
            "en_name": "recommenderIdentity",
            "zh_name": "上级经纪人身份",
            width:130
          },
          {
            "en_name": "agentName",
            "zh_name": "下级经纪人姓名",
            width:135
          },
          {
            "en_name": "agentMobile",
            "zh_name": "下级经纪人手机号",
            width:130
          },
          {
            "en_name": "inviteStatus",
            "zh_name": "邀约状态",
            render:(a, item, index, d, e, f)=>{
              return item.inviteStatus == 0 ? '已邀约' : item.inviteStatus == 1 ? '将失效' : '已失效'
            },
            width:130
          },
          {
            "en_name": "createTime",
            "zh_name": "邀约时间",
            width:130
          },
          {
            "en_name": "expireTime",
            "zh_name": "失效时间",
            width:130
          },
          {
            "en_name": "expireRemark",
            "zh_name": "失效原因",
            width:130
          },

          // {
          //   "en_name": "productNames",
          //   "zh_name": "推荐人项目",
          //   width:130,
          //   render:(a, item, index, d, e, f)=>{
          //     //console.log(item)
          //     if(item.productNames && item.productNames.length >0){
          //       return item.productNames.join('，')
          //     }
          //     return item.productNames
          //   }
          // },
          // {
          //   "en_name": "department",
          //   "zh_name": "推荐人部门",
          //   width:200,
          // },
          // {
          //   "en_name": "respectiveRegion",
          //   "zh_name": "所属区域",
          //   width:130,
          // },
          // {
          //   "en_name": "recommendNum",
          //   "zh_name": "推介客户数",
          // },
          // {
          //   "en_name": "devBrokerNum",
          //   "zh_name": "发展经纪人数",
          // },

          // {
          //   "en_name": "edit",
          //   "zh_name": "操作",
          //   render: (a, item, index, d, e, f) => {
          //     return (
          //       <span>
          //         <FlagBtn node={<a onClick={() => downLoad()}>导出</a>} btnId={'50203'}> </FlagBtn>
          //         {/* <a onClick={() => detailSkip('edit', item.accountId)}>查看</a> */}
          //       </span>
          //     )
          //   },
          // },
        ]
      },
    },
  }


  if (!!modelObj.biz) {
    pageProps.biz = modelObj.biz
    pageProps.biz.syncBackCbf = (biz) => {
      dispatch({
        type: `${namespace}/setFormVal`,
        payload: biz
      })
    }
  }
  return (
    <div className={cx('pageLayout')}>
      <ListPage pageProps={pageProps} />
      <Modal title={'请填写失效原因'}
          visible={ustdvisibe}
          okText={'确认'}
          cancelText={'取消'}
          // confirmLoading={() => }
          onCancel={(e) => {
             updateState({ ustdvisibe: false}) 
              // updateUploadModal()
          }}
          onOk={(e) => {
            dispatch({
              type: `${namespace}/remove`,
              payload: {}
            });
            // dispatch({
            //   type: `${namespace}/querylist`,
            //   payload: {}
            // });
            updateState({ ustdvisibe: false})
          }}
          width={720}><TextArea value={why} placeholder="请填写失效原因" onChange={e=>{inputChange(e.target.value)}} style={{marginBottom:'15px'}} rows={4} /></Modal>
    </div>
  )
}

export default connect(mapStateToProps)(Form.create()(View))
